package com.aqie.advanced.springApplication.bootstrap;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Spring 应用事件引导类
 * 使用SpringFramework 启动
 */
@Slf4j
public class SpringApplicationEventBootstrap {
    public static void main(String[] args) {
        // 创建上下文
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

        // 注册应用事件监听器
        context.addApplicationListener(event -> {
            log.info("监听到事件：{}",event);
        });

        // 启动上下文
        context.refresh();

        // 发送事件、
        context.publishEvent("Hello publish Event");        // PayloadApplicationEvent
        context.publishEvent(new ApplicationEvent("Aqie") {
        });
        context.close();
    }
}
